package org.gpp.proj1.demo.camera;

import java.io.IOException;

import org.gpp.proj1.camera.CameraDirector;
import org.gpp.proj1.camera.action.MoveToPointAction;
import org.gpp.proj1.map.GameMap;
import org.gpp.proj1.map.MalformedMapFileException;
import org.gpp.proj1.map.MapNode;
import org.gpp.proj1.map.parser.MapFileParser;
import org.gpp.proj1.map.renderer.MapNodeBuilder;

import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.CameraNode;
import com.jme.scene.Node;

public class CameraDemo extends SimpleGame {

	private CameraDirector director;
	
	public static void main(String[] args) {
		CameraDemo demo = new CameraDemo();
		demo.start();
	}

	@Override
	protected void simpleInitGame() {
		this.lightState.setGlobalAmbient( new ColorRGBA( 1.0f, 1.0f, 1.0f, 1.0f ) );
			
		Node centerNode = new Node("center");
		rootNode.attachChild( centerNode );
		
		GameMap map = null;
		try {
			map = MapFileParser.parseFile( "res/map/releaseMap.map" );
		} catch (IOException e) {
			e.printStackTrace();
		} catch (MalformedMapFileException e) {
			e.printStackTrace();
		}
		
		if( map != null ) {
			int width = map.getMapWidth();
			int height = map.getMapLength();
			
			rootNode.attachChild( MapNodeBuilder.buildNode( map ) );		
			
			centerNode.setLocalTranslation( new Vector3f( height * MapNode.TILE_SIZE / 2, 0, width * MapNode.TILE_SIZE / 2 ) );
		}		
		
		CameraNode camera = new CameraNode("CameraNode", cam);
		
		director = new CameraDirector( camera );
		director.setFocusedObject( centerNode );
		director.queueAction( new MoveToPointAction( camera, new Vector3f( 100, 150, 500 ), 4 ) );
		director.queueAction( new MoveToPointAction( camera, new Vector3f( 500, 200, 100 ), 3 ) );
		director.queueAction( new MoveToPointAction( camera, new Vector3f( 300, 350, 250 ), 3 ) );
	}

	@Override
	protected void simpleUpdate() {
		super.simpleUpdate();
		
		director.updateCamera( tpf );
	}
}
